import sys
import os
ROOT = '/home/shiyongxiang/'
PROOT = f'{ROOT}/pytools'
sys.path.append(PROOT)
sys.path.append(PROOT+'/libs')
sys.path.append(os.getcwd())

import os

DPI=600

LINES = {
    '2303':{
        'V1':[
            'DZ034', 'DZ035', 'DZ036', 'DZ037', 'DZ038', 'DZ039', 'DZ040', 
            'DZ041', 'DZ042', 'DZ043', 'DZ044', 'DZ045', 'DZ046', 'DZ047', 'DZ048', 'DZ049', 'DZ050', 
            'DZ051', 'DZ052', 'DZ053', 'DZ054', 'DZ055', 'DZ056', 'DZ057', 'DZ058', 'DZ059', 'DZ060', 
            'DZ061', 'DZ062', ],
        'H1':[
            'DZ001', 'DZ002', 'DZ003', 'DZ004', 'DZ005', 'DZ006', 'DZ007', 'DZ008', 'DZ009', 'DZ010', 
            'DZ011',          'DZ013',          'DZ015', 'DZ016', 'DZ017', 'DZ018', 'DZ019', 'DZ020', 
            'DZ021', 'DZ022', 'DZ023', 'DZ024', 'DZ025', 'DZ026', 'DZ027', 'DZ028', 'DZ029', 'DZ030', 
            'DZ031', 'DZ032',
        ],
        'H2':[
            'DZ091', 'DZ092', 'DZ093', 'DZ094', 'DZ095', 'DZ096',          'DZ098', 'DZ099', 'DZ100', 
            'DZ101', 'DZ102', 'DZ103', 'DZ104', 'DZ105', 'DZ106', 'DZ107', 'DZ108', 'DZ109', 'DZ110', 
            'DZ111', 'DZ112', 'DZ113', 'DZ114', 'DZ115', 'DZ116',
        ],
        'H1B':['DZ063', 'DZ064', 'DZ065', 'DZ066', 'DZ067', 'DZ068', 'DZ069', 'DZ070', 
            'DZ071', 'DZ072',],
        'H2B':['DZ073', 'DZ074', 'DZ075', 'DZ076', 'DZ077', 'DZ078', 'DZ079', 'DZ080',],  

        'HSR':[
            # dense
                            'DZ063', 'DZ064', 'DZ065', 'DZ066', 'DZ067', 'DZ068', 'DZ069', 'DZ070', 
            'DZ071', 'DZ072', 'DZ073', 'DZ074', 'DZ075', 'DZ076', 'DZ077', 'DZ078', 'DZ079', 'DZ080', 
            'DZ081', 'DZ082', 'DZ083', 'DZ084', 'DZ085', 'DZ086', 'DZ087', 'DZ088', 'DZ089', 'DZ090', 
            # SHORT
            'DZ151', 'DZ152', 'DZ153', 'DZ154', 'DZ155', 'DZ156', 'DZ157', 'DZ158', 'DZ159', 'DZ160'
        ],
        'VF':[
            'DZ132', 'DZ133', 'DZ134', 'DZ135', 'DZ136', 'DZ137', 'DZ138', 
            'DZ139', 'DZ141', 'DZ142', 'DZ143', 'DZ144', 'DZ145', 'DZ146',
        ],
        'HF':[
            'DZ117', 'DZ118', 'DZ119', 'DZ120', 'DZ121', 'DZ122', 'DZ123', 'DZ124', 'DZ125', 'DZ126', 
            'DZ127', 'DZ128', 'DZ129', 'DZ130', 'DZ131', 
        ],
        'HSRBN':[
            'DZ063','DZ064','DZ065','DZ066','DZ067','DZ068','DZ069'
        ],
        'ALL': [
            'DZ001', 'DZ002', 'DZ003', 'DZ004', 'DZ005', 'DZ006', 'DZ007', 'DZ008', 'DZ009', 'DZ010', 
            'DZ011',          'DZ013',          'DZ015', 'DZ016', 'DZ017', 'DZ018', 'DZ019', 'DZ020', 
            'DZ021', 'DZ022', 'DZ023', 'DZ024', 'DZ025', 'DZ026', 'DZ027', 'DZ028', 'DZ029', 'DZ030', 
            'DZ031', 'DZ032',          'DZ034', 'DZ035', 'DZ036', 'DZ037', 'DZ038', 'DZ039', 'DZ040', 
            'DZ041', 'DZ042', 'DZ043', 'DZ044', 'DZ045', 'DZ046', 'DZ047', 'DZ048', 'DZ049', 'DZ050', 
            'DZ051', 'DZ052', 'DZ053', 'DZ054', 'DZ055', 'DZ056', 'DZ057', 'DZ058', 'DZ059', 'DZ060', 
            'DZ061', 'DZ062', 'DZ063', 'DZ064', 'DZ065', 'DZ066', 'DZ067', 'DZ068', 'DZ069', 'DZ070', 
            'DZ071', 'DZ072', 'DZ073', 'DZ074', 'DZ075', 'DZ076', 'DZ077', 'DZ078', 'DZ079', 'DZ080', 
            'DZ081', 'DZ082', 'DZ083', 'DZ084', 'DZ085', 'DZ086', 'DZ087', 'DZ088', 'DZ089', 'DZ090', 
            'DZ091', 'DZ092', 'DZ093', 'DZ094', 'DZ095', 'DZ096',          'DZ098', 'DZ099', 'DZ100', 
            'DZ101', 'DZ102', 'DZ103', 'DZ104', 'DZ105', 'DZ106', 'DZ107', 'DZ108', 'DZ109', 'DZ110', 
            'DZ111', 'DZ112', 'DZ113', 'DZ114', 'DZ115', 'DZ116', 'DZ117', 'DZ118', 'DZ119', 'DZ120', 
            'DZ121', 'DZ122', 'DZ123', 'DZ124', 'DZ125', 'DZ126', 'DZ127', 'DZ128', 'DZ129', 'DZ130', 
            'DZ131', 'DZ132', 'DZ133', 'DZ134', 'DZ135', 'DZ136', 'DZ137', 'DZ138', 'DZ139', 'DZ140', 
            'DZ141', 'DZ142', 'DZ143', 'DZ144', 'DZ145', 'DZ146', 'DZ147', 'DZ148', 'DZ149', 'DZ150', 
            'DZ151', 'DZ152', 'DZ153', 'DZ154', 'DZ155', 'DZ156', 'DZ157', 'DZ158', 'DZ159', 'DZ160'
            ],
        'HSR_VALID': [
                            'DZ063', 'DZ064', 'DZ065', 'DZ066', 'DZ067', 'DZ068', 'DZ069', 'DZ070', 
            'DZ071', 'DZ072', 'DZ073', 'DZ074', 'DZ075', 'DZ076', 'DZ077', 'DZ078', 'DZ079', 'DZ080', 
            'DZ081', 'DZ082', 'DZ083', 'DZ084', 'DZ085', 'DZ086', 'DZ087', 'DZ088', 'DZ089', 'DZ090', 
            # SHORT
            'DZ154', 'DZ155', 'DZ156', 'DZ157', 'DZ158'],
        'DZ064L':[
            'DZ063', 'DZ064', 'DZ065', 'DZ066', 'DZ067', 'DZ068', 'DZ069', 'DZ070', 
            'DZ071', 'DZ072', 'DZ073', 'DZ074', 'DZ075', 'DZ076', 'DZ077', 'DZ078', 'DZ079', 'DZ080', 
            'DZ081', 'DZ082', 'DZ083', 'DZ084', 'DZ085', 'DZ086', 'DZ087', 'DZ088', 'DZ089', 'DZ090', 
            'DZ155',#'DZ156','DZ157'
        ],
        'VFHF':[
            # HF
            'DZ132', 'DZ133', 'DZ134', 'DZ135', 'DZ136', 'DZ137', 'DZ138', 'DZ139', 'DZ141', 'DZ142', 'DZ143', 'DZ144', 'DZ145', 'DZ146',
            # VF
            'DZ117', 'DZ118', 'DZ119', 'DZ120', 'DZ121', 'DZ122', 'DZ123', 'DZ124', 'DZ125', 'DZ126', 'DZ127', 'DZ128', 'DZ129', 'DZ130', 'DZ131', 
            # others
            'DZ146','DZ147', 'DZ148', 'DZ149', 'DZ150','DZ160',
            'DZ155','DZ156','DZ157','DZ158', 'DZ159'
        ],
        'VFHF_HSR':[
            # others
            'DZ146','DZ147', 'DZ148', 'DZ149', 'DZ150','DZ160',
            'DZ155','DZ156','DZ157','DZ158', 'DZ159'
        ],
        'VFHF_PURE':[
        # HF
        'DZ132', 'DZ133', 'DZ134', 'DZ135', 'DZ136', 'DZ137', 'DZ138', 'DZ139', 'DZ141', 'DZ142', 'DZ143', 'DZ144', 'DZ145', 'DZ146',
        # VF
        'DZ117', 'DZ118', 'DZ119', 'DZ120', 'DZ121', 'DZ122', 'DZ123', 'DZ124', 'DZ125', 'DZ126', 'DZ127', 'DZ128', 'DZ129', 'DZ130', 'DZ131', 
    ],
    },
    '2406':{
        '2406':[
                                        'P043', 'P044', 'P045', 'P046', 'P047', 'P048', 'P049', 
                'P050', 'P051', 'P052', 'P053', 'P054', 'P055', 'P056', 'P057', 'P058', 'P059', 
                'P060', 'P061', 'P062', 'P063', 'P064', 'P065', 'P066', 'P067', 'P068', 'P069', 
                'P070', 'P071', 'P072', 'P073', 'P074', 'P075', 'P076', 'P077', 'P078', 'P079', 
                'P080', 'P081', 'P082', 'P083', 'P084', 'P085', 'P086', 'P087', 'P088', 'P089', 
                'P090', 'P091', 'P092', 'P093', 'P094', 'P095', 'P096', 'P097', 'P098', 'P099', 
                'P100', 'P101', 'P102', 'P103', 'P104', 'P105', 'P106', 'P107', 'P108', 'P109', 
                'P110', 'P111', 'P112', 'P113', 'P114', 'P115', 'P116', 'P117', 'P118', 'P119', 
                'P120', 'P121', 'P122', 'P123', 'P124', 'P125', 'P126', 'P127', 'P128', 'P129', 
                'P130', 'P131', 'P132', 'P133', 'P134', 'P135', 'P136', 'P137', 'P138', 'P139', 
                'P140', 'P141', 'P142', 'P143', 'P144', 'P145', 'P146', 'P147', 'P148', 'P149', 
                'P150', 'P151', 'P152', 'P153', 'P154', 'P155', 'P156', 'P157', 'P158', 'P159', 
                'P160', 'P161', 'P162', 'P163', 'P164', 'P165', 'P166', 'P167', 'P168', 'P169', 
                'P170', 'P171', 'P172', 'P173', 'P174', 'P175', 'P176', 'P177', 'P178', 'P179', 
                'P180', 'P181', 'P182', 'P183', 'P184', 'P185', 'P186', 'P187', 'P188', 'P189', 
                'P190', 'P191', 'P192', 'P193', 'P194', 'P195', 'P196', 'P197', 'P198', 'P199', 
                'P200', 'P201', 'P202', 'P203', 'P204', 'P205', 'P206', 'P207', 'P208', 'P209', 
                'P210', 'P211', 'P212', 'P213', 'P214', 'P215', 'P216', 'P217', 'P218', 'P219', 
                'P220', 'P221', 'P222', 'P223', 'P224', 'P225', 'P226', 'P227', 'P228', 'P229', 
                'P230', 'P231', 'P232', 'P233', 'P234', 'P235', 'P236', 'P237', 'P238', 'P239', 
                'P240', 'P241', 'P242', 'P243', 'P244', 'P245', 'P246', 'P247', 'P248', 'P249', 
                'P250', 'P251', 'P252', 'P253', 'P254', 'P255', 'P256', 'P257', 'P258', 'P259', 
                'P260', 'P261', 'P262', 'P263', 'P264', 'P265', 'P266', 'P267', 'P268', 'P269', 
                'P270', 'P271', 'P272', 'P273', 'P274', 'P275', 'P276',                 'P279', 
                'P280', 'P281', 'P282', 'P283', 'P284', 'P285', 'P286', 'P287', 'P288', 'P289', 
                'P290', 'P291', 'P292', 'P293', 'P294', 'P295', 'P296', 'P297', 'P298', 'P299', 
                'P300', 'P301', 'P302', 'P303', 'P304', 'P305', 'P306', 'P307', 'P308', 'P309', 
                'P310', 'P311', 'P312', 'P313', 'P314', 'P315', 'P316', 'P317', 'P318', 'P319', 
                'P320', 'P321', 'P322', 'P323', 'P324', 'P325', 'P326', 'P327', 'P328', 'P329', 
                'P330', 'P331', 'P332', 'P333', 'P334', 'P335', 'P336', 'P337', 'P338', 'P339', 
                'P340', 'P341', 'P342', 'P343', 'P344', 'P345', 'P346', 'P347', 'P348', 'P349', 
                'E001', 'E002', 'E003', 'E004', 'E005', 'E006', 'E007', 'E008', 'E009', 'E010', 'E011', 
                'E021', 'E022', 'E023', 'E024'],

        'P250S':['P250', 'P251', 'P252', 'P253', 'P254', 'P255', 'P256', 'P257', 'P258', 'P259', 
                'P260', 'P261', 'P262', 'P263', 'P264', 'P265', 'P266', 'P267', 'P268', 'P269', 
                'P270', 'P271', 'P272', 'P273', 'P274', 'P275', 'P276',                 'P279', 
                'P280', 'P281', 'P282', 'P283', 'P284', 'P285', 'P286', 'P287', 'P288', 'P289', 
                'P290', 'P291', 'P292', 'P293', 'P294', 'P295', 'P296', 'P297', 'P298', 'P299', 
                'P300', 'P301', 'P302', 'P303', 'P304', 'P305', 'P306', 'P307', 'P308', 'P309', 
                'P310', 'P311', 'P312', 'P313', 'P314', 'P315', 'P316', 'P317', 'P318', 'P319', 
                'P320', 'P321', 'P322', 'P323', 'P324', 'P325', 'P326', 'P327', 'P328', 'P329', 
                'P330', 'P331', 'P332', 'P333', 'P334', 'P335', 'P336', 'P337', 'P338', 'P339', 
                'P340', 'P341', 'P342', 'P343', 'P344', 'P345', 'P346', 'P347', 'P348', 'P349'],
        'P264B':['P260', 'P261', 'P262', 'P263', 'P264', 'P265', 'P266', 'P267', 'P268', 'P269', 
                'P270', 'P271', 'P272', 'P273', 'P274', 'P275', 'P276'],
        'P264S':[                                'P264', 'P265', 'P266', 'P267', 'P268', 'P269', 
                'P270', 'P271', 'P272', 'P273', 'P274', 'P275', 'P276',                 'P279', 
                'P280', 'P281', 'P282', 'P283', 'P284', 'P285', 'P286', 'P287', 'P288', 'P289', 
                'P290', 'P291', 'P292', 'P293', 'P294', 'P295', 'P296', 'P297', 'P298', 'P299', 
                'P300', 'P301', 'P302', 'P303', 'P304', 'P305', 'P306', 'P307', 'P308', 'P309', 
                'P310', 'P311', 'P312', 'P313', 'P314', 'P315', 'P316', 'P317', 'P318', 'P319', 
                'P320', 'P321', 'P322', 'P323', 'P324', 'P325', 'P326', 'P327', 'P328', 'P329', 
                'P330', 'P331', 'P332', 'P333', 'P334', 'P335', 'P336', 'P337', 'P338', 'P339', 
                'P340', 'P341', 'P342', 'P343', 'P344', 'P345', 'P346', 'P347', 'P348', 'P349'],
                
        'P310S':[
                'P310', 'P311', 'P312', 'P313', 'P314', 'P315', 'P316', 'P317', 'P318', 'P319', 
                'P320', 'P321', 'P322', 'P323', 'P324', 'P325', 'P326', 'P327', 'P328', 'P329', 
                'P330', 'P331', 'P332', 'P333', 'P334', 'P335', 'P336', 'P337', 'P338', 'P339', 
                'P340', 'P341', 'P342', 'P343', 'P344', 'P345', 'P346', 'P347', 'P348', 'P349'],
        
        'P349N':['P264', 'P265', 'P266', 'P267', 'P268', 'P269', 
                'P270', 'P271', 'P272', 'P273', 'P274', 'P275', 'P276',                 'P279', 
                'P280', 'P281', 'P282', 'P283', 'P284', 'P285', 'P286', 'P287', 'P288', 'P289', 
                'P290', 'P291', 'P292', 'P293', 'P294', 'P295', 'P296', 'P297', 'P298', 'P299', 
                'P300', 'P301', 'P302', 'P303', 'P304', 'P305', 'P306', 'P307', 'P308', 'P309', 
                'P310', 'P311', 'P312', 'P313', 'P314', 'P315', 'P316', 'P317', 'P318', 'P319', 
                'P320', 'P321', 'P322', 'P323', 'P324', 'P325', 'P326', 'P327', 'P328', 'P329', 
                'P330', 'P331', 'P332', 'P333', 'P334', 'P335', 'P336', 'P337', 'P338', 'P339', 
                'P340', 'P341', 'P342', 'P343', 'P344', 'P345', 'P346', 'P347', 'P348', 'P349'
                ],
        
        'PIG':[
            'D0101', 'D0102', 'D0103', 'D0104', 'D0105', 'D0106', 'D0107', 'D0108', 'D0109', 'D0110', 'D0111', 'D0112', 'D0113', 'D0114', 'D2114', 'D0115', 'D0116', 'D0117', 'D0118', 'D0119', 'D0120', 'D0121', 'D0122', 'D0123', 'D0124', 'D0125', 'D0126', 
            'D0201', 'D0202', 'D0203', 'D0204', 'D0205', 'D0206', 'D0207', 'D0208', 'D0209', 'D0210', 'D0211', 'D0212', 'D0213', 'D0214', 'D0215', 'D0216', 'D0217', 'D0218', 'D0219', 'D0220', 'D0221', 'D0222', 'D0223', 'D0224', 
            'D0301', 'D0302', 'D0303', 'D0304', 'D0305', 'D0306', 'D0307', 'D0308', 'D0309', 'D0310', 'D0311', 'D0312', 'D0313', 'D0314', 
            'D0401', 'D0402', 'D0403', 'D0404', 'D0405', 'D0406', 'D0407', 'D0408', 'D0409', 'D0410', 'D0411', 'D0412', 'D0413', 'D0414', 
            'D0501', 'D0502', 'D0503', 'D0504', 'D0505', 'D0506', 'D0507', 'D0508', 'D0509', 'D0510', 'D0511', 'D0512', 'D0513', 'D0514', 
            'D0601', 'D0602', 'D0603', 'D0604', 'D0605', 'D0606', 'D0607', 'D0608', 'D0609', 'D0610', 'D0611', 'D0612', 'D0613', 'D0614', 
            'D0701', 'D0702', 'D0703', 'D0704', 'D0705', 'D0706', 'D0707', 'D0708', 'D0709', 'D0710', 'D0711', 'D0712', 'D0713', 'D0714', 
            'D0801', 'D0802', 'D0803', 'D0804', 'D0805', 'D0806', 'D0807', 'D0808', 'D0809', 'D0810', 'D0811', 'D0812', 'D0813', 'D0814', 
            'D0901', 'D0902', 'D0903', 'D0904', 'D0905', 'D0906', 'D0907', 'D0908', 'D0909', 'D0910', 'D0911', 'D0912', 'D0913', 'D0914', 
            'D1001', 'D1002', 'D1003', 'D1004', 'D1005', 'D1006', 'D1007', 'D1008', 'D1009', 'D1010', 'D1011', 'D1012', 'D1013', 'D1014', 
            'P0102', 'P0103', 'P0104'],
    },

    '254C':
    {
        '254C':['P006', 'P015', 'P030', 'P040', 'P050', 'P070', 'P080', 'P100', 'P124', 'P130', 
                'P150', 'P178', 'P192', 'P202', 'P210', 'P220', 'P230', 'P241', 'P250', 'P264', 
                'P273', 'P287', 'P291', 'P300', 'P320', 'P331', 'P340', 'P349', 'P401', 'P402',],
        'P250S':['P250', 'P264', 'P273', 'P287', 'P291', 'P300', 'P320', 'P331', 'P340', 'P349'],
        'P402N':['P250', 'P264', 'P273', 'P287', 'P291', 'P300', 'P320', 'P331', 'P340', 'P349','P402'],
        'P300S':['P300', 'P320', 'P349','P401'],
        'P320S':['P320', 'P349','P402'],
        'P349S':['P349','P402'],
        
    }
}

DAY_2023 = ['03.10','03.11','03.12','03.13','03.14','03.15','03.16','03.17','03.18','03.19','03.20','03.21','03.22','03.23','03.24','03.25','03.26','03.27','03.28','03.29']

def generate_dates(start_year_month, end_year_month):
    from datetime import datetime, timedelta
    """生成从start_year_month到end_year_month的所有日期，格式为YYMMDD"""
    start_date = datetime.strptime(start_year_month, "%y%m%d")  # 解析起始年月（如2410）
    end_date = datetime.strptime(end_year_month, "%y%m%d")      # 解析结束年月（如2505）
    
    current_date = start_date
    dates = []
    
    while current_date < end_date:
        dates.append(current_date.strftime("%y%m%d"))  # 格式化为YYMMDD
        current_date += timedelta(days=1)              # 增加1天
    
    return dates


DAY_254C = generate_dates("241014", "250409")
DAY_2406 = generate_dates("240530", "250626")


def get_info(DATE,CHN=0):

    from utils.loc import load_loc

    if DATE == '2303':
        days = DAY_2023
        H5_ROOT='data/2303.HSR'
        RAW_ROOT = f'{ROOT}/BAODING_RAW/2303/SAC100Hz'
        CHN_NAME='Z'
        s_info = load_loc('./loc/loc_all_from_log_2303.csv')
        START_TIME = '2023-03-10T00:00:00Z'
        NDAYS = 30
    elif DATE == '2406':
        days = DAY_2406
        H5_ROOT='data/2406.HSR'
        RAW_ROOT = f'{ROOT}/BAODING_RAW/2406/P320_H5_100Hz'
        CHN_NAME='Z'
        s_info = load_loc('./loc/loc_P320.csv',lat_key='lat',lon_key='lon')
        START_TIME = '2024-05-30T00:00:00Z'
        NDAYS = 30
    elif DATE == '2409':
        # Placeholder for 2409 data
        pass
    elif DATE == '254C':
        H5_ROOT='data/254C.HSR'
        RAW_ROOT = f'{ROOT}/BAODING_RAW/2425_4C/2425_H5'
        days = DAY_254C
        CHN_NAME = 'ENZH'[CHN]
        s_info = load_loc('./loc/254C.csv',lat_key='lat',lon_key='lon')
        START_TIME = '2024-10-08T00:00:00Z'
        NDAYS = 180
    else:
        raise ValueError(f"Unsupported DATE: {DATE}")
    
    LINES_new = LINES[DATE]

    date_info = {
        'DATE':DATE,
        'days': days,
        'H5_ROOT': H5_ROOT,
        'RAW_ROOT': RAW_ROOT,
        'CHN_NAME': CHN_NAME,
        's_info': s_info,
        'START_TIME': START_TIME,
        'NDAYS': NDAYS,
        'LINES': LINES_new
    }

    return date_info
